package com.反射;

/**
 * @Author CT
 * @Date 2021/6/14 11:22 下午
 */
public class 获取class类对象 {
    public static void main(String[] args) throws ClassNotFoundException {
        //使用类的class属性来获取该类对应的class对象
        Class<Student> c1 = Student.class;
        System.out.println(c1);

        Class<Student> c2 = Student.class;
        System.out.println(c1 == c2);
        System.out.println("--------");

        //调用对象的getClass方法，返回该对象的所属类对应class对象
        Student s = new Student();
        Class<? extends Student> c3 = s.getClass();
        System.out.println(c1 == c3);
        System.out.println("--------");

        //使用class类中的静态方法forName(String className)
        Class<?> c4 = Class.forName("com.反射.Student");
        System.out.println(c1 == c4);
    }
}
